package com.aios.action;

import java.util.Calendar;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;

import com.aios.entity.AbstractEntity;
import com.aios.util.Pager;

public class AbstractManagementAction extends AbstractAction {

	private static final long serialVersionUID = 1L;
	private static Logger logger = Logger.getLogger(AbstractManagementAction.class);
	
	public enum Mode {
		ADD, EDIT
	}

	protected String id;
	protected Pager pager;
	protected Integer pageStart = Pager.DEFAULT_PAGE_START;
	protected Integer pageSize = Pager.DEFAULT_PAGE_SIZE;
	protected Mode mode = Mode.ADD; // default
	protected String actionError;
	protected String actionMessage;
	protected boolean switchedUser = false; //default

	public Mode getMode() {
		return mode;
	}

	public void setMode(Mode mode) {
		this.mode = mode;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public Pager getPager() {
		return pager;
	}

	public void setPager(Pager pager) {
		this.pager = pager;
	}

	public Integer getPageStart() {
		return pageStart;
	}

	public void setPageStart(Integer pageStart) {
		this.pageStart = pageStart;
	}

	public Integer getPageSize() {
		return pageSize;
	}

	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}

	public void saveAddSettings(AbstractEntity entity) {
		Calendar calendar = Calendar.getInstance();

		entity.setInsertDatetime(calendar.getTime());
		entity.setUpdateDatetime(calendar.getTime());
		entity.setInsertUserId(getSessionUserVariable().getId());
		entity.setUpdateUserId(getSessionUserVariable().getId());
		entity.setStatus((byte) 0);

	}
	public void saveAddTimerSettings(AbstractEntity entity) {
		Calendar calendar = Calendar.getInstance();

		entity.setInsertDatetime(calendar.getTime());
		entity.setUpdateDatetime(calendar.getTime());
		entity.setInsertUserId(getSessionUserVariable().getId());
		entity.setUpdateUserId(getSessionUserVariable().getId());

	}

	public void saveEditSettings(AbstractEntity entity) {
		Calendar calendar = Calendar.getInstance();

		entity.setUpdateDatetime(calendar.getTime());
		entity.setUpdateUserId(getSessionUserVariable().getId());
	}

	public Pager setActionContext(Pager pager) {
		pager.setActionCallInfo(ServletActionContext.getActionMapping()
				.getName(), ServletActionContext.getActionMapping()
				.getNamespace(), ServletActionContext.getRequest()
				.getParameterMap());

		return pager;
	}

	public String getActionError() {
		return actionError;
	}

	public void setActionError(String actionError) {
		this.actionError = actionError;
	}

	public String getActionMessage() {
		return actionMessage;
	}

	public void setActionMessage(String actionMessage) {
		this.actionMessage = actionMessage;
	}

	public boolean isSwitchedUser() {
		return switchedUser;
	}

	public void setSwitchedUser(boolean switchedUser) {
		this.switchedUser = switchedUser;
	}

}
